// Package sys
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.17.8
package sys

import (
	"context"
	"fmt"
	"hotgo/api/admin/erp"
	"hotgo/internal/model/input/sysin"
	"hotgo/internal/service"
	"hotgo/utility/request"
)

var (
	Erp = cErp{}
)

type cErp struct{}

// List 查看erp列表
func (c *cErp) List(ctx context.Context, req *erp.ListReq) (res *erp.ListRes, err error) {
	var a request.ErpUtils
	//a.ErpLogin(ctx)
	StoreList, err := a.GetSYUserInfo(ctx)
	if err != nil {
		return nil, err
	}
	fmt.Println(StoreList, "StoreList123")
	resList, err := a.GetListInventoryBalanceStatusByLocation(ctx, "")
	if resList == nil {
		return nil, err
	}
	requestList := request.DeduplicateToDTO(resList.Data.Result)
	list, totalCount, err := service.SysErp().List(ctx, &req.ErpListInp)
	if err != nil {
		return
	}
	if list == nil {
		list = []*sysin.ErpListModel{}
	}
	fmt.Println(resList, "resList")
	res = new(erp.ListRes)
	res.List = list
	res.ErpList = requestList
	res.StoreList = StoreList
	res.PageRes.Pack(req, totalCount)
	return
}

// Export 导出erp列表
func (c *cErp) Export(ctx context.Context, req *erp.ExportReq) (res *erp.ExportRes, err error) {
	err = service.SysErp().Export(ctx, &req.ErpListInp)
	return
}

// Edit 更新erp
func (c *cErp) Edit(ctx context.Context, req *erp.EditReq) (res *erp.EditRes, err error) {
	err = service.SysErp().Edit(ctx, &req.ErpEditInp)
	return
}

// View 获取指定erp信息
func (c *cErp) View(ctx context.Context, req *erp.ViewReq) (res *erp.ViewRes, err error) {
	data, err := service.SysErp().View(ctx, &req.ErpViewInp)
	if err != nil {
		return
	}
	res = new(erp.ViewRes)
	res.ErpViewModel = data
	return
}

// Delete 删除erp
func (c *cErp) Delete(ctx context.Context, req *erp.DeleteReq) (res *erp.DeleteRes, err error) {
	err = service.SysErp().Delete(ctx, &req.ErpDeleteInp)
	return
}
